package com.example.workflow.listener;

import com.example.workflow.util.MailUtils;
import lombok.extern.slf4j.Slf4j;
import org.camunda.bpm.engine.delegate.DelegateTask;
import org.camunda.bpm.engine.delegate.TaskListener;
import org.springframework.stereotype.Component;

import java.awt.event.ActionListener;
import java.util.List;

@Slf4j
@Component
public class SubmitListener implements TaskListener {
    @Override
    public void notify(DelegateTask delegateTask) {
        // 获取任务相关的业务数据
        String taskId = delegateTask.getId();
        String assignee = delegateTask.getAssignee();
        String processInstanceId = delegateTask.getProcessInstanceId();
        String businessInstanceId = delegateTask.getExecution().getProcessBusinessKey();
        // 执行自定义业务逻辑，例如通知相关人员
        log.info("任务[ {} ]已经开始，businessInstanceId[ {} ]处理人员为: {}",taskId,businessInstanceId,assignee);

//        TODO 通知有关人员
//        List<String> assignees = (List<String>) delegateTask.getVariable("assignees");
//        MailUtils.sendMail(...);
    }
}
